﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using TestVisioCanvas.Wrappers;

namespace TestVisioCanvas.Helpers
{
    /// <summary>
    /// Helper class that encapsulates the management of the classes present on the drawing surface
    /// </summary>
    class ShapesManager
    {
        private ObservableCollection<IShape> shapes = new ObservableCollection<IShape>();

        /// <summary>
        /// Indexer for the shapes
        /// </summary>
        /// <param name="ID">ID of the requested shape</param>
        /// <returns>If a shape with that ID exists, it returns the correspondant IShape,
        /// if not it returns null</returns>
        public IShape this[int ID]
        {
            get { return shapes.FirstOrDefault(x => x.ID == ID); }            
        }
        
        /// <summary>
        /// Method that allows to add a not previously present shape into the collection.
        /// </summary>
        /// <param name="Shape">The shape to be added</param>
        /// <returns>True if the shape was added, false if it was already present</returns>
        public bool Add(IShape Shape)
        {
            if (this[Shape.ID]!=null)
            {
                shapes.Add(Shape);
                return true;
            }
            return false;
        }

        /// <summary>
        /// Method that allows to remove a previously present shape into the collection, choosen
        /// from its ID.
        /// </summary>
        /// <param name="ID">The ID of the shape to be removed</param>
        /// <returns>True if the shape was removed, false if it wasn't present in the collection</returns>
        public bool Remove(int ID)
        {
            if (this[ID] != null)
            {
                shapes.Remove(this[ID]);
                return true;
            }
            return false;
        }

        /// <summary>
        /// Method that allows to remove a previously present shape into the collection.
        /// </summary>
        /// <param name="Shape">The shape to be removed</param>
        /// <returns>True if the shape was removed, false if it wasn't present in the collection</returns>
        public bool Remove(IShape Shape)
        {
            if (this[Shape.ID] != null)
            {
                shapes.Remove(Shape);
                return true;
            }
            return false;
        }
    }
}
